<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%>

<!-- 搜索框 -->
功课类型：<select name="lessonStatus" id="lessonStatusSelected">
<option value="">全部</option>
<option value="0">必修</option>
<option value="1">非必修</option>
</select>
<input type="button" value="搜索" onclick="doSearch()"><br>
<!-- 搜索框 ==END==-->

<!-- datagrid数据表格 -->
<table id="myDatagridlesson"></table>
<!-- datagrid数据表格==END== -->

<!-- 按钮 -->
<div id="myBtnDivlesson">
    <a href="#" class="easyui-linkbutton" data-options="iconCls:'icon-add',plain:true" onclick="toOpenAdd()">添加必修功课</a>
    <a href="#" class="easyui-linkbutton" data-options="iconCls:'icon-remove',plain:true" onclick="toDelete()">批量删除</a>
</div>
<!-- 按钮===END=== -->


<!-- 添加对话框 -->
<div id="myAddDialogDivlesson" class="easyui-dialog" data-options="closed:true, width: 600, height: 400" >
    <form method="post" id="myFormlesson" enctype="multipart/form-data">
        功课名字：<input type="text" name="lessonName"/><br/><br/><br/><br/>
        <input type="hidden" name="userId" value="0">
        <input type="hidden" name="lessonStatus" value="0">
        <input type="button" value="添加" onclick="doAddSubmit()">
    </form>
</div>
<!-- 添加对话框===END=== -->




<script type="text/javascript">
    $(function (){

        /* datagrid展示数据 */
        $("#myDatagridlesson").datagrid({
            url:'${pageContext.request.contextPath}/lesson/showAll',
            pagination:true,
            columns:[[
                {checkbox:true},
                {field:'lessonId',title:'功课编号'},
                {field:'lessonName',title:'功课名字'}
            ]],
            toolbar: '#myBtnDivlesson'
        });
        /* datagrid展示数据  结束 */

    });



    /* 添加必修功课 */
    function toOpenAdd(){
        $('#myAddDialogDivlesson').dialog("open");
    };

    function doAddSubmit(){

        $('#myFormlesson').form('submit', {
            url:"${pageContext.request.contextPath}/lesson/add",
            success:function(data){
                var data=JSON.parse(data);
                if(data.flag){
                    $('#myAddDialogDivlesson').dialog("close");
                    $("#myDatagridlesson").datagrid("reload");
                }else{
                    $.messager.alert('提示框','添加失败，请确认！','warning');
                }
            }
        });
    }
    /* 添加必修功课 */

    /* 批量删除 */
    function toDelete(){
        var allSelectedRows=$("#myDatagridlesson").datagrid("getSelections");
        var ids=new Array();

        for(var i=0;i<allSelectedRows.length;i++){
            ids[i]=allSelectedRows[i].lessonId;
        }

        $.ajax({
            url:"${pageContext.request.contextPath}/lesson/delete",
            data:"ids="+ids,
            type:"post",
            dataType:"JSON",
            success:function(data){
                if(data.flag){
                    $("#myDatagridlesson").datagrid("reload");
                }else{
                    $.messager.alert('提示框','删除失败，请确认！','warning');
                }
            }
        });
    }
    /* 批量删除 */

    /* 搜索 */
    function doSearch(){
        var lessonStatus=$("#lessonStatusSelected").val();
        $("#myDatagridlesson").datagrid("reload",{"lessonStatus":lessonStatus});
    }
    /* 搜索结束*/

</script>